package com.ycy;

import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.upload.FastImageFile;
import com.github.tobato.fastdfs.service.DefaultFastFileStorageClient;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.Set;

@Component("fastFileStorageClient")
public class FastFileStorageClient extends DefaultFastFileStorageClient {

  @Override
  public StorePath uploadImageAndCrtThumbImage(InputStream inputStream,
                                               long fileSize,
                                               String fileExtName,
                                               Set<MetaData> metaDataSet) {
    FastImageFile fastImageFile;
    if (null == metaDataSet) {
      fastImageFile = new FastImageFile.Builder()
              .withFile(inputStream, fileSize, fileExtName)
              .withThumbImage()
              .toGroup("group2")
              .build();
    } else {
      fastImageFile = new FastImageFile.Builder()
              .withFile(inputStream, fileSize, fileExtName)
              .withMetaData(metaDataSet)
              .withThumbImage()
              .toGroup("group2")
              .build();
    }

    return uploadImage(fastImageFile);
  }

}
